package model.database;

import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class CalendarWrapper implements Comparable<CalendarWrapper> {	
	private GregorianCalendar time;

	public CalendarWrapper(long offset) {
		long toTimeMillis = ((new GregorianCalendar()).getTimeInMillis() + offset);
		GregorianCalendar time = new GregorianCalendar();
		time.setTimeInMillis(toTimeMillis);
		this.time = time;
	}

	public CalendarWrapper() {
		time = new GregorianCalendar();
	}

	public CalendarWrapper(Date date) {
		this.time = new GregorianCalendar();
		this.time.setTime(date);
	}

	public CalendarWrapper(String string) {
		try {
			java.util.Date date = new SimpleDateFormat().parse(string);
			this.time = new GregorianCalendar();
			this.time.setTime(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

	public String toString() {
		return getDateTime();
	}

	public String getDateTime() {
		return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(time.getTime());
	}

	public long timeMillis() {
		return time.getTimeInMillis();
	}

	public int compareTo(CalendarWrapper arg0) {
		return arg0.getDateTime().compareTo(this.getDateTime());
	}

	public void setTime(long millis) {
		this.time.setTimeInMillis(millis);
	}
}
